﻿using Developer.Core.Aggregation.Api.Models.UserService;
using Developer.Core.Aggregation.Api.Pos.UserService;
using Developer.Core.Aggregation.Api.Services.UserService;
using Elasticsearch.Net;
using Microsoft.AspNetCore.Mvc;
using System;

namespace Developer.Core.Aggregation.Api.Controllers
{
    [Route("api/Demo")]
    [ApiController]
    public class DemoController : ControllerBase
    {
        private readonly IUserClient userClient; 
        public DemoController(IUserClient userClient)
        {
            this.userClient = userClient; 
        }

        [HttpGet("Demo")]
        public User Get([FromForm] LoginPo loginPo)
        {
            var uris = new[]
            {
                new Uri("http://192.168.254.135:9200")
            }; 
            var connectionPool = new StaticConnectionPool(uris);
            var settings = new ConnectionConfiguration(connectionPool);

            var lowlevelClient = new ElasticLowLevelClient(settings);

            var searchResponse = lowlevelClient.Search<StringResponse>("canal", "_doc", PostData.Serializable(new
            {
                from = 0,
                size = 10,
                query = new
                {
                    match = new
                    {
                        name = loginPo.UserName,
                        age = loginPo.Age
                    }
                }
            }));

            var successful = searchResponse.Success;
            var responseJson = searchResponse.Body;


            return null;
        }
    }

    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
}
